﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using AutoPartsSearch.Domain.Abstract.Repositories;
using AutoPartsSearch.Domain.Common;
using AutoPartsSearch.Domain.Entities;

namespace AutoPartsSearch.Domain.Concrete.Repositories
{
    public class DapperContactRepository : IContactRepository
    {
        public int Add(Entities.Contact instance)
        {
            var param = new Dapper.DynamicParameters();
            param.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output);
            param.Add("@Name", instance.Name, DbType.String);
            param.Add("@Email", instance.Email, DbType.String);
            param.Add("@Phone", instance.Phone, DbType.String);
            param.Add("@Comments", instance.Comments, DbType.String);

            QueryExecutor.ExecuteProcedure("sp_AddContact", param);
            return param.Get<int>("@Id");
        }

        public void Update(Entities.Contact instance)
        {
            throw new NotImplementedException();
        }

        public Entities.Contact GetById(int id)
        {
            var param = new Dapper.DynamicParameters();
            param.Add("@Id", id, dbType: DbType.Int32);
            return QueryExecutor.QueryProcedure<Contact>("sp_GetContactsById", param).First();
        }

        public IEnumerable<Entities.Contact> Get()
        {
            return QueryExecutor.QueryProcedure<Contact>("sp_GetContacts");
        }

        public IEnumerable<Entities.Contact> Get(int page, int pageSize)
        {
            throw new NotImplementedException();
        }

        public void Delete(int id)
        {
            throw new NotImplementedException();
        }

        public long GetTotalCount()
        {
            throw new NotImplementedException();
        }
    }
}
